package server.world.item

case class Inventory( Hand1:Option[Weapon] = None,
                      Hand2:Option[OffHand] = None,
                      Armour:Option[BArmour] = None,
                      HeadGear:Option[HeadGear] = None,
                      Boots:Option[Boots] = None,
                      Neck:Option[Amulet] = None,
                      Ring1:Option[Ring] = None,
                      Ring2:Option[Ring] = None,
                      Quiver:Option[Quiver] = None){

def getDualWield() = if(!Hand1.isEmpty & !Hand2.isEmpty & Hand2.getOrElse(false).isInstanceOf[MeleeWeapon]) true else false
def checkTwoH():Boolean = Hand1.getOrElse(false).isInstanceOf[TwoHanded]

def getSlotStat[T](slot:Option[T], f: T => Float ):Float = slot.map(f).getOrElse(0f)

private def getArmourStats(f: Armour => Float):Float = getSlotStat(Armour, f) + getSlotStat(HeadGear, f) + getSlotStat(Boots, f) 
def getAC() = getArmourStats(Armour => Armour.ac)
def getEV() = getArmourStats(Armour => Armour.ev)

def contains(item:Item):Boolean =  if(Some(item) == Hand1 | 
                                      Some(item) == Hand2 |
                                      Some(item) == Armour |
                                      Some(item) == HeadGear |
                                      Some(item) == Boots |
                                      Some(item) == Neck |
                                      Some(item) == Ring1 |
                                      Some(item) == Ring2 |
                                      Some(item) == Quiver) true else false


}